/**
 * 
 */
package integercoding;

/**
 * @author ricardo
 * 
 */
public class EliasGamma {

	public static String encode(int number) {
		String code = "";
		double x = Math.log(number) / Math.log(2);
		double size = Math.floor(x);
		for (int i = 0; i < size; i++) {
			code += "0";
		}
		return code + Integer.toBinaryString(number);
	}

	public static int decode(String code) {
		return Integer.parseInt(code, 2);
	}
}
